<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ko">
<head>
    <meta http-equiv='Content-Type' content='text/html; charset=UTF-8'> 
    <title>Project Outland: </title>
	<link type="text/css" href="/static_media/css/outlandPoll/css/hot-sneaks/jquery-ui-1.7.1.custom.css" rel="stylesheet" /> 
    <link type="text/css" href="/static_media/css/outlandPoll.css" rel="stylesheet" />  

    
    <script type="text/javascript" src="/static_media/js/jquery-1.3.2.min.js"></script>
    <script type="text/javascript" src="/static_media/js/jquery-ui-1.7.1.custom.min.js"></script>

    <script type="text/javascript">
    var reco = {}
    var selectedShop = ''
    function menudivFadeIn(){ $('#menu_div').fadeIn(500);}
    function addMenu(item)
    {
        window_height = document.documentElement.clientHeight;
        if(selectedShop != item)
        {
            $('#menu_div').stop(false,true)
            $('#menulist').stop(false,true)
            $('#blank').css('height',window_height+'px');
            selectedShop = item;
            $('#menu_div').hide();
            $('#menulist').hide();

       $.get('/outland/poll/ajaxHtml/menu/'+encodeURI(item),
                function(data)
                {
                $('#menu_div').queue(function(){
                    $('#menu_div').html($('<div></div>').attr('id','menulist').html(data));
                    $('#menulist').show();
                    menudivFadeIn();
                    $(this).dequeue();
                    })
                $('.reco').click(function(){
                    $(this).children().trigger('click'); 
                        }).css('cursor','pointer');
                })
        }
    }
    function writeReco(shop,menu,value)
    {
/*        if(!reco[shop])
        {
            reco[shop]={};
        }
        reco[shop][menu]=value;*/
        $('#'+shop+'_'+menu+'_'+'no').removeClass('reco-no-activate');
        $('#'+shop+'_'+menu+'_'+'dono').removeClass('reco-dono-activate');
        $('#'+shop+'_'+menu+'_'+'yes').removeClass('reco-yes-activate');
        $('#'+shop+'_'+menu+'_'+value).addClass('reco-'+value+'-activate');
        $('input').attr("disabled","disabled");
        $.ajax({type:"POST",
                url: "/outland/poll/save",
                data: {'value':value,'shopid':shop,'menuid':menu},
                dataType : 'text',
                success: function(res)
                {
                    if(res == "Success")
                    {
                    }
                    else
                    {
                    alert(res);
                    }
                    $('input').attr("disabled","");
                },
                error: function()
                {
                    alert('failed');
                    $('input').attr("disabled","");
                }
                });

    }
    function saveResult()
    {
        gen = {};
        for(shop in reco)
        {
            for(menu in reco[shop])
            {
               gen[shop+'___'+menu] = reco[shop][menu]; 
            }
        }
        $.getJSON('/outland/poll/save',gen,function(data){alert(data.s)});
    } 

    function hideLoading()
    {
        $('#loading').hide();
    }
    function showLoading()
    {
        $('#loading').css('top',(document.documentElement.clientHeight || document.body.clientHeight) / 2 + (blah = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop) - 30 + "px");
        $('#loading').show();
    }

    function amp(s)
    {
    return s.replace(/&/g,'%26')
    }
    $(function(){
            $.ajaxSetup({ scriptCharset: "utf-8" , contentType: "application/json; charset=utf-8", cache:false});
            $('#menu_div').hide()

            $('#cate_div').tabs({spinner: ''
                ,select: function(event, ui) {
                $('#menu_div').hide()
                $('#menulist').hide()
                selectedShop = '';
                showLoading()
                }
                ,load: function(event, ui) {
                hideLoading();
                }
                });
		    $.getJSON('/outland/poll/json/category',
            function(data)
            {
                $.each(data.name_list,
                    function(i,item)
                    {
					$('#cate_div').tabs('add','/outland/poll/ajaxHtml/shop/'+amp(amp(encodeURI(item))),item);
                    }
                    );
            }
            );
            $('#submitButton').click(
            function()
            {
            saveResult()
            return false;
            });

            $().ajaxStart(showLoading).ajaxStop(hideLoading);
            $('#loading').hide();

        }
        );

    </script>

</head>

<body>
    <div id='loading'>
        <div id='loading-cont'>
            <img src='/static_media/poll/loading.gif'>
        </div>
    </div>
<div id='wrap'>
<div id='header'>
    <a href="/outland/poll"><img src="/static_media/poll/title.gif" border=0></a>
    <a href="/outland/poll/logout"> Logout </a>
</div>

<div id='container'>
    
<div id="cate_div">
    <ul id="cate_list">
    </ul>
</div>

<div id='menu_div' class='ui-tabs ui-widget ui-widget-content ui-corner-all'>
</div>
<div id='blank'>
</div>
</div><!-- ends-->

</div><!--warp ends-->
</body>

</html>
